<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        /**
         * Cookie用法
         */ 
        // document.cookie = 'name=tom'

        // var date = new Date()
        // date.setDate(date.getDate() + 7)
        // document.cookie = 'age=18; expires=' + date.toUTCString()

        // console.log(document.cookie)


        /**
         * localStorage和sessionStoreage
         */ 

        // localStorage.setItem('name', 'tom')
        // console.log(localStorage.getItem('name'))


        // sessionStorage.setItem('age', '18')
        // console.log(sessionStorage.getItem('age'))

        var user = {
            name: 'tom',
            age: 18
        }

        localStorage.setItem('user', JSON.stringify(user))

        var obj = JSON.parse(localStorage.getItem('user'))
        console.log(obj)
    </script>
</head>
<body>
    
</body>
</html>